package button;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.MouseEvent;

import button.*;

//
public class ChoiceButtonGroup{
	private MyButton[] buttons = null;
	private int x;
	private int y;
	
	public ChoiceButtonGroup(MyButton[] choices, int x, int y){
		super();
		if(choices.length == 4){
			buttons = choices;
		}else{
			System.out.println("button missed!");
		}
		randomButton();
		this.x = x;
		this.y = y;
		setEachButtonsPosition();
	}
	

	private void randomButton(){
		MyButton[] tempButtons = new ChoiceButton[4];
		int temp;
		for(int i = 0; i < 4; i++){
			temp = (int)(Math.random() * 10)%3;
			if(buttons[temp] != null){
				tempButtons[i] = buttons[temp];
				buttons[temp] = null;
			}else{
				for(int k = 3; k >= 0; k--){
					if(buttons[k] != null){
						tempButtons[i] = buttons[k];
						buttons[k] = null;
					}
				}
			}
		}
		buttons = tempButtons;
	}
	
	public void display(Graphics g){
		for(int i = 3; i >= 0; i--){
			buttons[i].draw((Graphics2D)g);
		}
	}
	
	public void setEachButtonsPosition(){
		buttons[0].setX(x);
		buttons[0].setY(y);
		buttons[1].setX(x + buttons[1].getWidth());
		buttons[1].setY(y);
		buttons[2].setX(x );
		buttons[2].setY(y + buttons[2].getHeight());
		buttons[3].setX(x + buttons[3].getWidth());
		buttons[3].setY(y + buttons[3].getHeight());
	}
	
	public void setButtonInactive(){
		for(int i = 0; i < 4; i++){
			buttons[i].setActiveFalse();
		}
	}
	
	public void pressed(MouseEvent e){
		for(int i = 0; i < 4; i++){
			buttons[i].pressed(e);
		}
	}
	public void released(MouseEvent e){
		for(int i = 0; i < 4; i++){
			buttons[i].released(e);
		}
	}
}
